upstream {{ item.name }} {
    server {{ item.endpoint }} max_fails=0;
}

server {
    listen       80;
    server_name  {{ item.domain }};
    location / {
        proxy_pass http://{{ item.name }}/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-Scheme $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        # WebSocket support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_connect_timeout 5;
        proxy_read_timeout 120s;
        proxy_next_upstream error;
    }
}